package com.jarvis.pzz.modules.findshop;

import android.Manifest;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.support.v7.view.ContextThemeWrapper;
import android.support.v7.widget.PopupMenu;
import android.telephony.PhoneNumberUtils;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jarvis.pzz.R;
import com.jarvis.pzz.common.BaseActivity;
import com.jarvis.pzz.common.ResponseData;
import com.jarvis.pzz.models.InitFindShopModel;
import com.jarvis.pzz.models.ShopsListByFilterModel;
import com.jarvis.pzz.modules.completed.ReleaseCompletedActivity;
import com.jarvis.pzz.modules.findshop.adapter.FindshopAdapter;
import com.jarvis.pzz.modules.findshop.model.FindDateModel;
import com.jarvis.pzz.modules.findshop.model.FindDemandModel;
import com.jarvis.pzz.modules.findshop.model.FindFacilitiesModel;
import com.jarvis.pzz.modules.findshop.model.FindTransferModel;
import com.jarvis.pzz.seervers.RequestService;
import com.jarvis.pzz.util.SharePreferenceKey;
import com.jarvis.pzz.util.SharePreferenceUtils;
import com.jarvis.pzz.util.net.RequestApi;
import com.jarvis.pzz.widget.ScrollGridView;
import com.tbruyelle.rxpermissions.RxPermissions;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import butterknife.BindView;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import rx.functions.Action1;

public class FindShopActivity extends BaseActivity implements View.OnClickListener {
    @BindView(R.id.rel_left)
    RelativeLayout rel_left;
    @BindView(R.id.lin_title)
    RelativeLayout lin_title;

    @BindView(R.id.ll_spinner_zj)
    LinearLayout ll_spinner_zj;
    @BindView(R.id.et_min_money)
    EditText et_min_money;
    @BindView(R.id.et_max_money)
    EditText et_max_money;
    @BindView(R.id.ll_spinner_qy)
    LinearLayout ll_spinner_qy;
    @BindView(R.id.et_find_name)
    EditText et_find_name;
    @BindView(R.id.et_find_phone)
    EditText et_find_phone;
    @BindView(R.id.ll_spinner_jy)
    LinearLayout ll_spinner_jy;
    @BindView(R.id.et_find_life)
    EditText et_find_life;
    @BindView(R.id.et_find_demand)
    TextView et_find_demand;
    @BindView(R.id.ll_spinner_zrf)
    LinearLayout ll_spinner_zrf;
    @BindView(R.id.et_find_floor)
    EditText et_find_floor;
    @BindView(R.id.sgv_ss)
    ScrollGridView sgv_ss;
    @BindView(R.id.et_find_explain)
    EditText et_find_explain;
    @BindView(R.id.tv_find_publish)
    TextView tv_find_publish;
    @BindView(R.id.ll_demand)
    LinearLayout ll_demand;
    @BindView(R.id.et_find_area)
    EditText et_find_area;
    @BindView(R.id.et_find_max_area)
    EditText et_find_max_area;
    @BindView(R.id.et_find_shop)
    EditText et_find_shop;
    @BindView(R.id.tv_money)
    TextView tv_money;

    @BindView(R.id.tv_find_zj)
    TextView tv_find_zj;
    @BindView(R.id.tv_find_qy)
    TextView tv_find_qy;
    @BindView(R.id.tv_find_jy)
    TextView tv_find_jy;
    @BindView(R.id.tv_find_zrf)
    TextView tv_find_zrf;

    private String find_zj = "1";//租金
    private String find_qy = "";//期望区域
    private String find_jy = "";//计划经营
    private String find_zrf = "";//转让费
    private String find_bz = "";//是否办证

    private List<FindFacilitiesModel> findFacilitiesModels;
    private FindshopAdapter findshopAdapter;

    private List<InitFindShopModel.ShopModelDean> shopModelDeen;
    private List<InitFindShopModel.areaListBean> areaListBeen;
    private List<FindDateModel> findDateModels;
    private List<FindTransferModel> findTransferModels;
    private List<FindDemandModel> findDemandModels;
    private RequestService service;

    @Override
    public int getLayoutId() {
        return R.layout.activity_find_shop;
    }

    @Override
    public void initData() {
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
        sgv_ss.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, final int position, long id) {
                ImageView imageView = (ImageView) view.findViewById(R.id.iv_img);
                imageView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (findFacilitiesModels.get(position).isState()) {
                            findFacilitiesModels.get(position).setState(false);
                            findshopAdapter.notifyDataSetChanged(findFacilitiesModels);
                        } else {
                            findFacilitiesModels.get(position).setState(true);
                            findshopAdapter.notifyDataSetChanged(findFacilitiesModels);
                        }


                    }
                });
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });

    }

    @Override
    public void initView() {
        setBar();
        setListener();
        service = RequestApi.create(RequestService.class);
        tv_find_zj.setText("月租金");
        tv_find_qy.setText("请选择");
        tv_find_jy.setText("请选择");
        tv_find_zrf.setText("请选择");
        findFacilitiesModels = new ArrayList<>();
        shopModelDeen = new ArrayList<>();
        areaListBeen = new ArrayList<>();
        findDateModels = new ArrayList<>();
        findTransferModels = new ArrayList<>();
        findDemandModels = new ArrayList<>();
        getphoto();//加载图片
        findshopAdapter = new FindshopAdapter(findFacilitiesModels, this);
        sgv_ss.setAdapter(findshopAdapter);
        getInitFindShop();
        getdate();
        getTransfer();
        getDemand();


    }

    /**
     * 设置监听事件
     */
    public void setListener() {
        rel_left.setOnClickListener(this);
        ll_spinner_zj.setOnClickListener(this);
        ll_spinner_qy.setOnClickListener(this);
        ll_spinner_jy.setOnClickListener(this);
        ll_spinner_zrf.setOnClickListener(this);
        tv_find_publish.setOnClickListener(this);
        ll_demand.setOnClickListener(this);


    }
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_BACK)) {
            AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this)
                    .setTitle("铺找找温馨提示")
                    .setMessage("老板 确定要离开吗？")
                    .setNegativeButton("狠心离开", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            finish();
                        }
                    })
                    .setPositiveButton("继续留下", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    });

            dialogBuilder.create().show();
            return false;
        }else {
            return super.onKeyDown(keyCode, event);
        }

    }
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.rel_left:
                AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this)
                        .setTitle("铺找找温馨提示")
                        .setMessage("老板 确定要离开吗？")
                        .setNegativeButton("狠心离开", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                finish();
                            }
                        })
                        .setPositiveButton("继续留下", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                            }
                        });

                dialogBuilder.create().show();
                break;
            case R.id.ll_spinner_zj:
                //租金选择
                setdatePopupMenu(ll_spinner_zj);
                break;
            case R.id.ll_spinner_qy:
                //期望区域
                setareaListBeenPopupMenu(ll_spinner_qy);
                break;
            case R.id.ll_spinner_jy:
                //计划经营
                setshopModelDeenPopupMenu(ll_spinner_jy);
                break;
            case R.id.ll_spinner_zrf:
                //转让费
                setTransferPopupMenu(ll_spinner_zrf);
                break;
            case R.id.ll_demand:
                //是否办证
                setDemandPopupMenu(ll_demand);
                break;
            case R.id.tv_find_publish:
                //发布需求
                if (getvalue()) {
                    getaddFindShop();
                }
                break;

        }
    }

    private void setBar() {
        lin_title.setVisibility(View.VISIBLE);
        lin_title.getBackground().setAlpha(255);
        int statusBarHeight1 = -1;
        //获取status_bar_height资源的ID
        int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            //根据资源ID获取响应的尺寸值
            statusBarHeight1 = getResources().getDimensionPixelSize(resourceId);
        }
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(lin_title.getLayoutParams());
        lp.setMargins(0, statusBarHeight1, 0, 0);
        lin_title.setLayoutParams(lp);
    }


    private void getDemand() {
        FindDemandModel findDemandModel = new FindDemandModel();
        findDemandModel.setName("是");
        findDemandModel.setState("1");
        findDemandModels.add(findDemandModel);
        FindDemandModel findDemandModel2 = new FindDemandModel();
        findDemandModel2.setName("否");
        findDemandModel2.setState("0");
        findDemandModels.add(findDemandModel2);

    }


    private void getTransfer() {
        FindTransferModel findTransferModel = new FindTransferModel();
        findTransferModel.setName("有转让费");
        findTransferModel.setState("1");
        findTransferModels.add(findTransferModel);
        FindTransferModel findTransferModel2 = new FindTransferModel();
        findTransferModel2.setName("无转让费");
        findTransferModel2.setState("0");
        findTransferModels.add(findTransferModel2);
    }


    private void getdate() {
        FindDateModel dateModel = new FindDateModel();
        dateModel.setName("月租金");
        dateModel.setState("1");
        findDateModels.add(dateModel);
        FindDateModel dateModel1 = new FindDateModel();
        dateModel1.setName("年租金");
        dateModel1.setState("0");
        findDateModels.add(dateModel1);

    }

    private void getphoto() {
        //上水
        FindFacilitiesModel findFacilitiesModel6 = new FindFacilitiesModel();
        findFacilitiesModel6.setImg_yes(R.drawable.icon_shangshui_press);
        findFacilitiesModel6.setImg_no(R.drawable.icon_shangshui);
        findFacilitiesModel6.setState(false);
        findFacilitiesModel6.setId("9");
        findFacilitiesModels.add(findFacilitiesModel6);

        //下水
        FindFacilitiesModel findFacilitiesModel9 = new FindFacilitiesModel();
        findFacilitiesModel9.setImg_yes(R.drawable.icon_xiashui_press);
        findFacilitiesModel9.setImg_no(R.drawable.icon_xiashui);
        findFacilitiesModel9.setState(false);
        findFacilitiesModel9.setId("11");
        findFacilitiesModels.add(findFacilitiesModel9);

        //380
        FindFacilitiesModel findFacilitiesModel2 = new FindFacilitiesModel();
        findFacilitiesModel2.setImg_yes(R.drawable.icon_dian_press);
        findFacilitiesModel2.setImg_no(R.drawable.icon_dian);
        findFacilitiesModel2.setState(false);
        findFacilitiesModel2.setId("12");
        findFacilitiesModels.add(findFacilitiesModel2);

        //煤气罐
        FindFacilitiesModel findFacilitiesModel3 = new FindFacilitiesModel();
        findFacilitiesModel3.setImg_yes(R.drawable.icon_meiqi_press);
        findFacilitiesModel3.setImg_no(R.drawable.icon_meiqi);
        findFacilitiesModel3.setState(false);
        findFacilitiesModel3.setId("13");
        findFacilitiesModels.add(findFacilitiesModel3);

        //烟管道
        FindFacilitiesModel findFacilitiesModel10 = new FindFacilitiesModel();
        findFacilitiesModel10.setImg_yes(R.drawable.icon_yan_press);
        findFacilitiesModel10.setImg_no(R.drawable.icon_yan);
        findFacilitiesModel10.setState(false);
        findFacilitiesModel10.setId("14");
        findFacilitiesModels.add(findFacilitiesModel10);

        //排污管道
        FindFacilitiesModel findFacilitiesModel4 = new FindFacilitiesModel();
        findFacilitiesModel4.setImg_yes(R.drawable.icon_pai_press);
        findFacilitiesModel4.setImg_no(R.drawable.icon_pai);
        findFacilitiesModel4.setState(false);
        findFacilitiesModel4.setId("15");
        findFacilitiesModels.add(findFacilitiesModel4);
        //停车位
        FindFacilitiesModel findFacilitiesModel5 = new FindFacilitiesModel();
        findFacilitiesModel5.setImg_yes(R.drawable.icon_park_press);
        findFacilitiesModel5.setImg_no(R.drawable.icon_park);
        findFacilitiesModel5.setState(false);
        findFacilitiesModel5.setId("16");
        findFacilitiesModels.add(findFacilitiesModel5);

        //天然气
        FindFacilitiesModel findFacilitiesModel7 = new FindFacilitiesModel();
        findFacilitiesModel7.setImg_yes(R.drawable.icon_tianranqi_press);
        findFacilitiesModel7.setImg_no(R.drawable.icon_tianranqi);
        findFacilitiesModel7.setState(false);
        findFacilitiesModel7.setId("17");
        findFacilitiesModels.add(findFacilitiesModel7);

        //外摆设
        FindFacilitiesModel findFacilitiesModel8 = new FindFacilitiesModel();
        findFacilitiesModel8.setImg_yes(R.drawable.icon_waibai_press);
        findFacilitiesModel8.setImg_no(R.drawable.icon_waibai);
        findFacilitiesModel8.setState(false);
        findFacilitiesModel8.setId("18");
        findFacilitiesModels.add(findFacilitiesModel8);

        //可明火
        FindFacilitiesModel findFacilitiesModel = new FindFacilitiesModel();
        findFacilitiesModel.setImg_yes(R.drawable.icon_fire_press);
        findFacilitiesModel.setImg_no(R.drawable.icon_fire);
        findFacilitiesModel.setState(false);
        findFacilitiesModel.setId("19");
        findFacilitiesModels.add(findFacilitiesModel);

    }

    //11.发布求租/买铺信息初始化
    private void getInitFindShop() {
        String user_id = SharePreferenceUtils.getString(SharePreferenceKey.USER_ID);

        Call<ResponseData<InitFindShopModel>> shopsListByFilter = service.getInitFindShop(user_id);
        shopsListByFilter.enqueue(new Callback<ResponseData<InitFindShopModel>>() {
            @Override
            public void onResponse(Call<ResponseData<InitFindShopModel>> call, Response<ResponseData<InitFindShopModel>> response) {

                if (response.body() != null) {
                    int total_count = response.body().getTotalcount();
                    int resultCode = response.body().getResultCode();
                    if (resultCode == 200) {
                        shopModelDeen = response.body().getData().getRunIndustryList();
                        areaListBeen = response.body().getData().getAreaList();
                    } else {
                        showTextToast(response.body().getMessage());
                    }
                } else {
                    showTextToast("请求失败");
                }
            }

            @Override
            public void onFailure(Call<ResponseData<InitFindShopModel>> call, Throwable t) {
                showTextToast(RequestApi.detailError(t));
            }
        });
    }

    //12 发布求租信息
    private void getaddFindShop() {
        int money = Integer.valueOf(et_min_money.getText().toString());
        int max_money = Integer.valueOf(et_max_money.getText().toString());
        int area = Integer.valueOf(et_find_area.getText().toString());
        int max_area = Integer.valueOf(et_find_max_area.getText().toString());
        String name = et_find_name.getText().toString();
        String phone = et_find_phone.getText().toString();
        String reqIntroduce = et_find_explain.getText().toString();
        String life = et_find_life.getText().toString();
        String floor = et_find_floor.getText().toString();
        final String shop = et_find_shop.getText().toString();
        String stall = null;

        for (int i = 0; i < findFacilitiesModels.size(); i++) {
            if (findFacilitiesModels.get(i).isState()) {
                if (stall == null) {
                    stall = findFacilitiesModels.get(i).getId();
                } else {
                    stall += "," + findFacilitiesModels.get(i).getId();
                }
            }

        }


        Call<ResponseData> responseDataCall = service.getaddFindShop("2", find_zj, money, max_money,
                area, max_area, find_qy, name, phone, find_jy, reqIntroduce, life, find_bz, find_zrf, floor, shop, stall);
        responseDataCall.enqueue(new Callback<ResponseData>() {
            @Override
            public void onResponse(Call<ResponseData> call, Response<ResponseData> response) {
                if (response.body() != null) {
                    int total_count = response.body().getTotalcount();
                    int resultCode = response.body().getResultCode();
                    if (resultCode == 200) {
                        getRentShopList();
                    } else {
                        showTextToast(response.body().getMessage());
                    }
                } else {
                    showTextToast("请求失败");
                }
            }

            @Override
            public void onFailure(Call<ResponseData> call, Throwable t) {
                showTextToast(RequestApi.detailError(t));
            }
        });

    }

    //14.发布找铺信息成功后,点击”发布完成”返回匹配的list(转铺)
    private void getRentShopList() {

        int money = Integer.valueOf(et_min_money.getText().toString());
        int max_money = Integer.valueOf(et_max_money.getText().toString());
        int area = Integer.valueOf(et_find_area.getText().toString());
        int max_area = Integer.valueOf(et_find_max_area.getText().toString());
        String name = et_find_name.getText().toString();
        String phone = et_find_phone.getText().toString();
        final String reqIntroduce = et_find_explain.getText().toString();
        String life = et_find_life.getText().toString();
        String floor = et_find_floor.getText().toString();
        final String shop = et_find_shop.getText().toString();
        String stall = null;

        for (int i = 0; i < findFacilitiesModels.size(); i++) {
            if (findFacilitiesModels.get(i).isState()) {
                if (stall == null) {
                    stall = findFacilitiesModels.get(i).getId();
                } else {
                    stall += "," + findFacilitiesModels.get(i).getId();
                }
            }

        }


        Call<ResponseData<ShopsListByFilterModel>> responseDataCall = service.getRentShopList("2", find_zj, money, max_money,
                area, max_area, find_qy, name, phone, find_jy, reqIntroduce, life, find_bz, find_zrf, floor, shop, stall);
        responseDataCall.enqueue(new Callback<ResponseData<ShopsListByFilterModel>>() {
            @Override
            public void onResponse(Call<ResponseData<ShopsListByFilterModel>> call, Response<ResponseData<ShopsListByFilterModel>> response) {
                if (response.body() != null) {
                    int total_count = response.body().getTotalcount();
                    int resultCode = response.body().getResultCode();
                    if (resultCode == 200) {

                        Intent intent=new Intent(mActivity,ReleaseCompletedActivity.class);
                        intent.putExtra("RENT_SHOP_LIST", (Serializable) response.body().getData().getShopList());
                        startActivity(intent);
                        finish();


                        finish();
                    } else {
                        showTextToast(response.body().getMessage());
                    }
                } else {
                    showTextToast("请求失败");
                }
            }

            @Override
            public void onFailure(Call<ResponseData<ShopsListByFilterModel>> call, Throwable t) {
                showTextToast(RequestApi.detailError(t));
            }
        });

    }





    private boolean getvalue() {

        if (TextUtils.isEmpty(et_min_money.getText().toString())) {
            showTextToast("请输入最小租金");
            return false;
        }

        if (TextUtils.isEmpty(et_max_money.getText().toString())) {
            showTextToast("请输入最大租金");
            return false;
        }

        if (Integer.valueOf(et_min_money.getText().toString()) > Integer.valueOf(et_max_money.getText().toString())) {
            showTextToast("最小租金不能大于最大租金");
            return false;
        }


        if (TextUtils.isEmpty(et_find_area.getText().toString())) {
            showTextToast("请输入最小面积需求");
            return false;
        }

        if (TextUtils.isEmpty(et_find_max_area.getText().toString())) {
            showTextToast("请输入最大面积需求");
            return false;
        }

        if (Integer.valueOf(et_find_area.getText().toString()) > Integer.valueOf(et_find_max_area.getText().toString())) {
            showTextToast("最小面积不能大于最大面积");
            return false;
        }

        if (find_qy.equals("")) {
            showTextToast("请选择期望区域");
            return false;
        }

        if (TextUtils.isEmpty(et_find_name.getText().toString())) {
            showTextToast("请输入姓名");
            return false;
        }

        if (TextUtils.isEmpty(et_find_phone.getText().toString())) {
            showTextToast("请输入号码");
            return false;
        }

        if (!isPhoneNumber(et_find_phone.getText().toString())) {
            showTextToast("请输入正确号码");
            return false;
        }

        return true;
    }

    /**
     * 判断手机号是否符合规范
     * @param phoneNo 输入的手机号
     * @return
     */
    public static boolean isPhoneNumber(String phoneNo) {
        if (TextUtils.isEmpty(phoneNo)) {
            return false;
        }
        if (phoneNo.length() == 11) {
            for (int i = 0; i < 11; i++) {
                if (!PhoneNumberUtils.isISODigit(phoneNo.charAt(i))) {
                    return false;
                }
            }
            Pattern p = Pattern.compile("^((13[^4,\\D])" + "|(134[^9,\\D])" +
                    "|(14[5,7])" +
                    "|(15[^4,\\D])" +
                    "|(17[3,6-8])" +
                    "|(18[0-9]))\\d{8}$");
            Matcher m = p.matcher(phoneNo);
            return m.matches();
        }
        return false;
    }

    //计划经营
    private void setshopModelDeenPopupMenu(View view) {
        Context wrapper = new ContextThemeWrapper(mActivity, R.style.PopupMenuStyle);
        final PopupMenu popupMenu = new PopupMenu(wrapper, view);
        for (int i = 0; i < shopModelDeen.size(); i++) {
            popupMenu.getMenu().add(0, i, 0, shopModelDeen.get(i).getIndustryName()).setTitleCondensed(String.valueOf(shopModelDeen.get(i).getIndustryId()));
        }
        popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            public boolean onMenuItemClick(MenuItem item) {
                String productName = item.getTitle().toString();
                find_jy = item.getTitleCondensed().toString();
                tv_find_jy.setText(productName);
                return true;
            }
        });
        popupMenu.show();
    }

    //期望区域
    private void setareaListBeenPopupMenu(View view) {
        Context wrapper = new ContextThemeWrapper(mActivity, R.style.PopupMenuStyle);
        final PopupMenu popupMenu = new PopupMenu(wrapper, view);
        for (int i = 0; i < areaListBeen.size(); i++) {
            popupMenu.getMenu().add(0, i, 0, areaListBeen.get(i).getName()).setTitleCondensed(String.valueOf(areaListBeen.get(i).getId()));
        }
        popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            public boolean onMenuItemClick(MenuItem item) {
                String productName = item.getTitle().toString();
                find_qy = item.getTitleCondensed().toString();
                tv_find_qy.setText(productName);
                return true;
            }
        });
        popupMenu.show();
    }


    //月租金/年租金
    private void setdatePopupMenu(View view) {
        Context wrapper = new ContextThemeWrapper(mActivity, R.style.PopupMenuStyle);
        final PopupMenu popupMenu = new PopupMenu(wrapper, view);
        for (int i = 0; i < findDateModels.size(); i++) {
            popupMenu.getMenu().add(0, i, 0, findDateModels.get(i).getName()).setTitleCondensed(findDateModels.get(i).getState());
        }
        popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            public boolean onMenuItemClick(MenuItem item) {
                String productName = item.getTitle().toString();
                find_zj = item.getTitleCondensed().toString();
                tv_find_zj.setText(productName);
                if(find_zj.equals("0")){
                    tv_money.setText("万元/年");
                }else if(find_zj.equals("1")) {
                    tv_money.setText("元/月");
                }



                return true;
            }
        });
        popupMenu.show();
    }

    //转让费
    private void setTransferPopupMenu(View view) {
        Context wrapper = new ContextThemeWrapper(mActivity, R.style.PopupMenuStyle);
        final PopupMenu popupMenu = new PopupMenu(wrapper, view);
        for (int i = 0; i < findTransferModels.size(); i++) {
            popupMenu.getMenu().add(0, i, 0, findTransferModels.get(i).getName()).setTitleCondensed(findTransferModels.get(i).getState());
        }
        popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            public boolean onMenuItemClick(MenuItem item) {
                String productName = item.getTitle().toString();
                find_zrf = item.getTitleCondensed().toString();
                tv_find_zrf.setText(productName);
                return true;
            }
        });
        popupMenu.show();
    }

    //是否办证
    private void setDemandPopupMenu(View view) {
        Context wrapper = new ContextThemeWrapper(mActivity, R.style.PopupMenuStyle);
        final PopupMenu popupMenu = new PopupMenu(wrapper, view);
        for (int i = 0; i < findDemandModels.size(); i++) {
            popupMenu.getMenu().add(0, i, 0, findDemandModels.get(i).getName()).setTitleCondensed(findDemandModels.get(i).getState());
        }
        popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            public boolean onMenuItemClick(MenuItem item) {
                String productName = item.getTitle().toString();
                find_bz = item.getTitleCondensed().toString();
                et_find_demand.setText(productName);
                return true;
            }
        });
        popupMenu.show();
    }
}
